import {routerRedux} from 'dva/router';
import {login} from '../services/login';
import {parse} from 'qs';

export default {
    namespace: 'login',
    state: {
        showError: false,   //显示错误
    },
    effects: {
        *login({payload}, {call, put}) {
            const {data} = yield call(login, payload);
            if (data.msg == '0') {  //0代表成功,其他值代表失败
                localStorage.setItem('authToken',data.data.authToken)
                yield put(routerRedux.push('/user'));
            }
            else {
                yield put({type: 'showError'});
            }
        },
    },
    reducers: {
        showError(state) {
            return {...state, showError: true};
        },
    },

};
